require(["./config"], () => {
  require(["swiper", "url", "template", "header", "footer"], (
    Swiper,
    url,
    template
  ) => {
    class Index {
      constructor() {
        this.banner();
        this.renderBanner();
        this.renderContents();
        this.renderContent();
      }
      banner() {
        new Swiper(".swiper-container", {
          loop: true,
          // autoplay: true,

          // 如果需要分页器
          pagination: ".swiper-pagination",

          // 如果需要前进后退按钮
          nextButton: ".swiper-button-next",
          prevButton: ".swiper-button-prev"
        });
      }
      renderBanner() {
        $.get(url.baseUrl + "/index", resp => {
          if (resp.code === 200) {
            const { index } = resp.body;
            // console.log(index);
            $("#banner").html(template("getbanner", { list: index }));
          }
        });
      }
      renderContents() {
        $.get(url.baseUrl + "/content", resp => {
          console.log(resp);
          if (resp.code === 200) {
            const { content } = resp.body;

            $("#contents").html(template("getcontents", { list: content }));
          }
        });
      }
      renderContent() {
        $.get(url.baseUrl + "/content", resp => {
          console.log(resp);
          if (resp.code === 200) {
            const { content } = resp.body;

            $("#content").html(template("getcontent", { list: content }));
          }
        });
      }
    }
    new Index();
  });
});
